<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/html/js/axios.min.js"></script>
    <script src="/html/js/ajax.js"></script>
    <script src="/html/js/util.js"></script>
    <script>
        var id =0;
        window.onload = function (){
            //得到上前一页面传递的参数
            id = getQuery("id");
            init(id);
        }

        async function init(id){
            var deptList = await ajaxGet("/dept/findAll");
            var emObj = await ajaxGet("/employee/findById",{id});
            var str = "";
            for(var i=0;i<deptList.length;i++){
                var obj = deptList[i];
                str += `<option value="${obj.id}">${obj.name}</option>`;
            }
            $("deptSelect").innerHTML = str;

            //完成页面元素的初始化
            $("nameSpan").innerHTML = emObj.name;
            $("birthdaySpan").innerHTML = emObj.birthday;
            $("money").value = emObj.money;
            $("deptSelect").value = emObj.dept.id;
        }

        async function update(){
            var obj = {
                id,
                deptId:$("deptSelect").value,
                money:$("money").value
            }
            var info = await ajaxGet("/employee/update",obj);
            if(info == "ok"){
               location.href = "/html/index.html";
            }
            else{
                alert("修改失败");
            }
        }
    </script>
</head>
<body>
    姓名：<span id="nameSpan"></span><br>
    生日：<span id="birthdaySpan"></span><br>
    工资：<input type="text" id="money"><br>
    部门：<select id="deptSelect"></select>
    <input type="button" value="修改" onclick="update()">
</body>
</html>